home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
rjs.lha
/
RJS
/
String
/
tests
/
StringSearch.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-06-14
|
2KB
|
87 lines
#include <iostream.h>
#include <ctype.h>
#include "RJS/String.h"
int num_fail=0, num_pass=0;
#define Assert(cond) if (!(cond)) num_fail++,cerr << "Assert(" << __LINE__ << ") Failed." << endl; else num_pass++;
#include <ctype.h>
class SSwhitespace : public StringSearch {
public:
SSwhitespace(){}
int search(const String &s, int &matchlen) const ;
};
int SSwhitespace::search(const String &s, int &len) const
{
len=0;
int p1;
StringIterator next(s);
char ch;
while (next(ch))
if (isspace(ch)) {
p1=next.pos();
while (next(ch) && isspace(ch));
len=next.pos()-p1;
return p1;
}
return -1;
}
int SearchInt(const String &s, int &len) const
{
len=0;
int pos=0,p1;
StringIterator next(s);
char ch;
while (next(ch)) if (isdigit(ch) || ch=='-') {
p1=next.pos();
while (next(ch) && isdigit(ch));
len=next.pos()-p1;
return p1;
}
return -1;
}
const SSwhitespace SSwhite;
const StringSearch Sint(SearchInt);
void main()
{
//String s1("This be a test");
//s1.at(SSwhite)=" ";
//cout << s1 << endl;
//s1="this is 1234,not abc";
//s1.at(Sint)="one two three four";
//cout << s1 << endl;
String s1("one two three four");
cout << "s1.after('three') ==> " << s1.after("three") << endl;
(s1.at("three")) += "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
cout << s1 << endl;
s1="one two three four";
(s1.substr(0).substr(13,0)) += "AAAAAAAAAAAAAAAAAAAA";
cout << s1 << endl;
//cout << "Number of tests that passed ==> " << num_pass << endl;
//cout << "Number of tests that failed ==> " << num_fail << endl;
}